package com.example.freshmenclient.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.freshmenclient.R;
import com.example.freshmenclient.bean.LeavewordsBean;
import com.example.freshmenclient.util.UrlUtil;

import java.util.List;

public class LeaveWordAdapter extends BaseAdapter {

    private Context context;
    private List<LeavewordsBean.DataBean> data;

    public LeaveWordAdapter(Context context, List<LeavewordsBean.DataBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = View.inflate(context, R.layout.item_leaveword, null);

        TextView tvleavewordName = convertView.findViewById(R.id.tv_leaveword_name);
        TextView tvleavewords = convertView.findViewById(R.id.tv_leaveword);
        TextView tvleavewordDate = convertView.findViewById(R.id.tv_leaveword_date);

        if (data.get(position).getUser().getId() == UrlUtil.userId) {
            tvleavewordName.setGravity(Gravity.RIGHT);
        }
        tvleavewordName.setText(data.get(position).getUser().getName());
        tvleavewords.setText(data.get(position).getContent());
        tvleavewordDate.setText(data.get(position).getDate());
        return convertView;
    }
}
